package com.netease.nim.uikit.business.session.emoji;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.netease.nim.uikit.R;
import com.netease.nim.uikit.common.leadbean.SentenceBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 话术的适配器
 */
public class SentenceAdapter2 extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;

    private int startIndex;

    private List<SentenceBean> dataList = new ArrayList<>();



    public SentenceAdapter2(Context mContext, int startIndex) {
        this.context = mContext;
        this.startIndex = startIndex;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SentenceAdapter2.TransHolder(LayoutInflater.from(context).inflate(R.layout.item_sentence_list, null));
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        final SentenceBean bean = dataList.get(position);
        ((SentenceAdapter2.TransHolder)holder).title.setText(bean.getName());
        if(mOnItemClickListener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickListener.onItemClick(bean.getName(),holder.getLayoutPosition());
                }
            });
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void setDataList(List<SentenceBean> languageBeanlist) {
        this.dataList = languageBeanlist;
        notifyDataSetChanged();
    }

    class TransHolder extends RecyclerView.ViewHolder {

        TextView title;

        TransHolder(View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.title);
        }
    }

    onItemClickListener mOnItemClickListener;

    public interface onItemClickListener {
        void onItemClick(String content, int position);
    }

    public void setOnItemClickLitsener(onItemClickListener mOnItemClickLitsener) {
        mOnItemClickListener= mOnItemClickLitsener;
    }

}